#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef int QElemType_t;

struct node
{
    QElemType_t  data;
    struct node *next;
};
struct node *head;

void queue_init()
{
    //1、申请头节点
    head = malloc(sizeof(struct node));

    head->next = NULL;
}

//尾插 -入队
void push(QElemType_t data)
{
    //1、申请新节点
    struct node *newNode = malloc(sizeof(struct node));
    newNode->data = data;
    newNode->next = NULL;
    //2、找到尾节点
    struct node *tail = head;
    while(tail->next != NULL)
    {
        tail = tail->next;
    }
    //3、将新节点插入到尾节点后面
    tail->next = newNode;
    
}

bool isEmpty()
{
    //1、判断队列是否为空
    return head->next == NULL;
}

//头删
void pop(QElemType_t *data)
{
    //1、判断队列是否为空
    if(isEmpty())
    {
        printf("队列为空\n");
        return;
    }
    //先记住当前的数据首节点
    struct node *cur = head->next;
    *data = cur->data;
    //2、将头节点指向下一个节点
    head->next = head->next->next;
    free(cur);
}

int main()
{
    queue_init();
    push(1);
    push(2);
    push(3);
    push(4);
    push(5);

    while(1){
        QElemType_t data;
        pop(&data);
        printf("%d\n",data);

        if(isEmpty()){
            break;
        }
    }


    return 0;
}